<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>出价防扰设置</title>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/page.css">
    <script src="../js/jquery-3.2.1.min.js"></script>
    <script src="../js/media.js"></script>
    <script src="../js/common.js"></script>
    <style>

    </style>
</head>

<body>
    <!--头部-->
    <div class="public-header flex">
        <!--<span class="public-header-left-search"></span>-->
        <span class="public-header-left-back"></span>
        <span class="public-header-center">出价防扰设置</span>
        <span class="public-header-right">保存</span>
    </div>

    <!--正文-->
    <div class="Bidding-settings bc-gray">
        <section class="section1">
            <ul>
                <li class="flex">
                    <span>首次出价需要认证手机号</span>
                    <div class="checkbox checkbox-slider--b-flat">
                        <!--<label>-->
				            <!--<input type="checkbox" class="" id="op"><span></span>-->
			            <!--</label>-->
                        <img id="op"  on="0" src="../img/选择%201@2x.png" style="width: 40px;height: 20px;">
                    </div>
                </li>

            </ul>
        </section>

        <section class="section2" style="display: none;">
            <ul>
                <li class="flex">
                    <span>违约率小于30%<font style="font-size:.08rem;">(2笔以上)</font></span>
                    <div class="checkbox checkbox-slider--b-flat">
                        <img id="op1"  on="0" src="../img/选择%201@2x.png" style="width: 40px;height: 20px;">

                        <!--<label>-->
				<!--<input type="checkbox" class="" id="op1"><span></span>-->
			<!--</label>-->
                    </div>
                </li>
                <li class="flex" >
                    <span>买家支付系统保证金</span>
                    <em  id="haha" data-se='1' >勾</em>
                </li>
                <li class="flex" >
                    <span>买家禁止出价</span>
                    <em  data-se='2' id="hahas">勾</em>
                </li>

            </ul>
        </section>

        <section class="section3" style="display: none;">
            <ul>
                <li class="flex">
                    <span>退货比率小于30% <font style="font-size:.08rem;">(2笔以上)</font></span>
                    <div class="checkbox checkbox-slider--b-flat">
                        <img id="op2"  on="0" src="../img/选择%201@2x.png" style="width: 40px;height: 20px;">

                    </div>
                </li>
                <li class="flex">
                    <span>买家支付系统保证金</span>
                    <em  data-se='1' id="haha2">勾</em>
                </li>
                <li class="flex">
                    <span>买家禁止出价</span>
                    <em  data-se='2' id="haha2s">勾</em>
                </li>

            </ul>
        </section>

    </div>




    <script>
        var is_first = 0;
        var is_first_Msg = 0;
        var ok1 = 1;
        var ok2 = 1;
        var default_rate = 0;
        $(function () {
            $('#op').click(function () {
                var $on = $(this).attr("on");

                if($on == 1){
                    $(this).attr("on",0);
                    $(this).attr("src","../img/选择%201@2x.png");
                    $(this).attr("class","");
                }else{
                    $(this).attr("on",1);
                    $(this).attr("src","../img/选择%202@2x.png")
                    $(this).attr("class","checked");

                }
            })
            $('#op1').click(function (){
                var $on = $(this).attr("on");
                if($on == 1){
                    $(this).attr("on",0);
                    $(this).attr("src","../img/选择%201@2x.png");
//                    $(this).parent().parent().find('em').removeClass('active')
                    $(".section2").find('em').removeClass('active');
                }else{
                    $(this).attr("on",1);
                    $(this).attr("src","../img/选择%202@2x.png")

                }
            });
            $('#op2').click(function () {
                var $on = $(this).attr("on");
                if($on == 1){
                    $(this).attr("on",0);
                    $(this).attr("src","../img/选择%201@2x.png");
                    $(".section3").find('em').removeClass('active');
                }else{
                    $(this).attr("on",1);
                    $(this).attr("src","../img/选择%202@2x.png")

                }
            })
            $('.section2 li:gt(0)').click(function () {
                if ($('#op1').attr('on') == 1) {
                    $(this).find('em').toggleClass('active').closest('li').siblings().find('em').removeClass(
                        'active');
                }
            })
            $('.section3 li:gt(0)').click(function () {
                if ($('#op2').attr('on') == 1) {
                    $(this).find('em').toggleClass('active').closest('li').siblings().find('em').removeClass(
                        'active');
                }
            })
            $('.public-header-right').click(function () {
                var is_first, is_first_Msg, default_rate;
    
                if ($('#op').hasClass('checked')) {
                    is_first = 1
                } else {
                    is_first = 0
                }

        
                if ($('#op1').attr('on') == 1){
                    if ($('.section2 li:gt(0) em').hasClass('active') == false) {
                        alert('请选择一个违约率的选项')
                        ok1 = 0;
                    }else{
                        ok1 = 1;
                        is_first_Msg = $('.section2 .active').data('se');
                    }


                }else{
                    is_first_Msg = 0;
                    ok1 = 1;
                }
                if ($('#op2').attr('on') == 1) {
                    if ($('.section3 li:gt(0) em').hasClass('active') == false) {
                        alert('请选择一个退货率的选项')
                        ok2 = 0;
                    }else{
                        ok2 = 1;
                        default_rate = $('.section3 .active').data('se');
                    }
                }else{
                    default_rate = 0;
                    ok2 = 1;
                }
                //alert(ok1+","+ok2);
                if (ok1 == 1 && ok2 == 1) {
                    console.log(is_first,is_first_Msg,default_rate)
                    $.ajax({
                        url: base_url + 'ZITAOHUI/store/antiDisturbance',
                        data: {
                            store_id: sessionStorage.getItem("s_id"),
        
                            is_first: is_first,
                           
                            is_first_Msg: is_first_Msg,
               
                            default_rate: default_rate,
                        },
                        success:function(data){
                            console.log(data)
                            if(data.code == 1){
                                alert("设置成功");
                                window.location.href = '../page/setting-center.html'
                            }
                        }
                    })
                }

            })

        })
        getcj();
        function getcj (){
            //获取是否设置过
            $.ajax({
                url:base_url+"ZITAOHUI/store/msg",
                data:{
                    store_id:sessionStorage.getItem("s_id")
                },
                dataType:"json",
                success:function (data){
                    console.log(data);
                    var _d = data.extend.list;
                    if(_d.is_first){
                        $("#op").attr("on",1);
                        $("#op").attr("src","../img/选择%202@2x.png");
                        $("#op").attr("class","checked");
                    }
                    if(_d.is_first_Msg == 1){
                        $("#op1").attr("on",1);
                        $("#op1").attr("src",'../img/选择%202@2x.png');
                        $("#haha").attr('class','active');

                    }
                    if(_d.is_first_Msg == 2){
                        $("#op1").attr("on",1);
                        $("#op1").attr("src",'../img/选择%202@2x.png');
                        $("#hahas").attr('class','active');
                    }
                    if(_d.default_rate == 1){
                        $("#op2").attr("on",1);
                        $("#op2").attr("src",'../img/选择%202@2x.png');
                        $("#haha2").attr('class','active');
                    }
                    if(_d.default_rate == 2){
                        $("#op2").attr("on",1);
                        $("#op2").attr("src",'../img/选择%202@2x.png');
                        $("#haha2s").attr('class','active');
                    }
                }
            })

        }

    </script>
</body>

</html>